package com.heima.article.listen;

import com.heima.common.article.HotArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author mrchen
 * @date 2022/8/9 11:07
 */
@Component
@Slf4j
public class HotArticleScoreListener {
    @Autowired
    StringRedisTemplate redisTemplate;

    @RabbitListener(queuesToDeclare = @Queue(HotArticleConstants.HOT_ARTICLE_SCORE_BEHAVIOR_QUEUE))
    public void handleHotArticleBehaviorMsg(String behaviorJson){
        log.info(" 接收到  新增行为消息   消息内容: {}",behaviorJson);
        redisTemplate.opsForList().rightPush(
                HotArticleConstants.HOT_ARTICLE_SCORE_BEHAVIOR_LIST,
                behaviorJson
        );
    }
}
